package com.laicunba.ext.web.controller.console.sys;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.laicunba.ext.web.controller.BaseController;
import com.laicunba.pojo.UserDO;
import com.laicunba.service.UserService;
import com.laicunba.service.mq.ActiveMQService;
import com.laicunba.util.StringUtil;

@Controller
@RequestMapping(value = "/console/ext/sys")
public class JmsCreateCouponController extends BaseController {

	@Autowired
	private UserService userService;
	@Autowired
	private ActiveMQService activeMQService;

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/jms_create_coupon.htm")
	public String jmsCreateCoupon(String mobile, String cash_def_id, String rate_def_id, String summary) {
		JSONObject json = new JSONObject();
		UserDO userDO = userService.findByMobile(mobile);
		if (userDO == null) {
			json.put("code", "USER_NOT_EXIST");
			return json.toJSONString();
		}

		JSONObject msg = new JSONObject();

		msg.put("uid", userDO.getId());
		//msg.put("cash_def_id", cash_def_id);
		msg.put("summary", summary);
		
		if(StringUtil.isNotEmpty(cash_def_id)){
			msg.put("cash_def_id", cash_def_id);
		}
		if(StringUtil.isNotEmpty(rate_def_id)){
			msg.put("rate_def_id", rate_def_id);
		}
		activeMQService.sendQueues("lcb.core.action.create.coupon", msg.toJSONString(), StringUtil.genGUID());
		json.put("code", "SUCCESS");
		return json.toJSONString();

	}
}
